package com.etc.web;

import com.etc.pojo.AuthPo;
import com.etc.pojo.Authority;
import com.etc.pojo.CodeMessage;
import com.etc.pojo.CustomPo;
import com.etc.service.QuanXianService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("api")
public class QuanXianController {


    @Autowired
    QuanXianService service;

    @RequestMapping(value = "getAllQuanxianList.action", produces = "application/json;charset=UTF-8")
    public String getAllQuanxianList(@RequestParam("uname") String uname){


        List<CustomPo> list = service.findAllQuanxian(uname);
        CodeMessage cm = new CodeMessage();
        ObjectMapper om = new ObjectMapper();
        cm.setCode("200");
        cm.setData(list);
        String result = null;
        try {
            result = om.writeValueAsString(cm);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        return result;

    }



    @RequestMapping(value = "getAllQuanxianList1.action", produces = "application/json;charset=UTF-8")
    public String getAllQuanxianList1(){

        List<Authority> list = service.findAllQuanxian1();
        CodeMessage cm = new CodeMessage();
        ObjectMapper om = new ObjectMapper();
        cm.setCode("200");
        cm.setData(list);
        String result = null;
        try {
            result = om.writeValueAsString(cm);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        return result;

    }


    @RequestMapping(value = "updatequanxian.action", produces = "application/json;charset=UTF-8")
    public String updatequanxian(@RequestBody() HashMap param){
        System.out.println(param);
        service.updateQuanxian(param);
        CodeMessage cm = new CodeMessage();
        ObjectMapper om = new ObjectMapper();
        cm.setCode("200");
        cm.setData(null);
        String result = null;
        try {
            result = om.writeValueAsString(cm);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        return result;

    }
}
